/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.httpclient.HttpClientUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import junit.framework.TestCase;
/*     */ import org.apache.commons.httpclient.Header;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpException;
/*     */ import org.apache.commons.httpclient.HttpMethod;
/*     */ import org.apache.commons.httpclient.StatusLine;
/*     */ import org.apache.commons.httpclient.methods.GetMethod;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestWsdlServlet
/*     */   extends TestCase
/*     */ {
/*     */   private static final String wsdlUrlBase = "/service/wsdl/";
/*     */   
/*     */   String doWsdlServletRequest(String wsdlUrl, boolean admin, int expectedCode)
/*     */     throws Exception
/*     */   {
/*  39 */     Server localServer = Provisioning.getInstance().getLocalServer();
/*     */     String protoHostPort;
/*     */     String protoHostPort;
/*  42 */     if (admin) {
/*  43 */       protoHostPort = "https://localhost:" + localServer.getIntAttr("zimbraAdminPort", 0);
/*     */     } else {
/*  45 */       protoHostPort = "http://localhost:" + localServer.getIntAttr("zimbraMailPort", 0);
/*     */     }
/*  47 */     String url = protoHostPort + wsdlUrl;
/*     */     
/*  49 */     HttpClient client = new HttpClient();
/*  50 */     HttpMethod method = new GetMethod(url);
/*     */     try
/*     */     {
/*  53 */       int respCode = HttpClientUtil.executeMethod(client, method);
/*  54 */       int statusCode = method.getStatusCode();
/*  55 */       String statusLine = method.getStatusLine().toString();
/*     */       
/*  57 */       ZimbraLog.test.debug("respCode=" + respCode);
/*  58 */       ZimbraLog.test.debug("statusCode=" + statusCode);
/*  59 */       ZimbraLog.test.debug("statusLine=" + statusLine);
/*     */       
/*  61 */       assertTrue("Response code", respCode == expectedCode);
/*  62 */       assertTrue("Status code", statusCode == expectedCode);
/*     */       
/*  64 */       Header[] respHeaders = method.getResponseHeaders();
/*  65 */       String header; for (int i = 0; i < respHeaders.length; i++) {
/*  66 */         header = respHeaders[i].toString();
/*  67 */         ZimbraLog.test.debug("ResponseHeader:" + header);
/*     */       }
/*     */       
/*  70 */       String respBody = method.getResponseBodyAsString();
/*     */       
/*  72 */       return respBody;
/*     */     }
/*     */     catch (HttpException e) {
/*  75 */       fail("Unexpected HttpException" + e);
/*  76 */       throw e;
/*     */     } catch (IOException e) {
/*  78 */       fail("Unexpected IOException" + e);
/*  79 */       throw e;
/*     */     } finally {
/*  81 */       method.releaseConnection();
/*     */     }
/*     */   }
/*     */   
/*     */   public void testWsdlServletZimbraServicesWsdl() throws Exception {
/*  86 */     String body = doWsdlServletRequest("/service/wsdl/ZimbraService.wsdl", false, 200);
/*  87 */     assertTrue("Body contains expected string", body.contains("wsdl:service name="));
/*     */   }
/*     */   
/*     */   public void testWsdlServletZimbraUserServicesWsdl() throws Exception {
/*  91 */     String body = doWsdlServletRequest("/service/wsdl/ZimbraUserService.wsdl", false, 200);
/*  92 */     assertTrue("Body contains expected string", body.contains("wsdl:service name="));
/*     */   }
/*     */   
/*     */   public void testWsdlServletZimbraAdminServicesWsdl() throws Exception {
/*  96 */     String body = doWsdlServletRequest("/service/wsdl/ZimbraAdminService.wsdl", true, 200);
/*  97 */     assertTrue("Body contains expected string", body.contains("wsdl:service name="));
/*     */   }
/*     */   
/*     */   public void testWsdlServletXsd() throws Exception {
/* 101 */     String body = doWsdlServletRequest("/service/wsdl/zimbraAccount.xsd", false, 200);
/* 102 */     assertTrue("Body contains expected string", body.contains(":schema>"));
/*     */   }
/*     */   
/*     */   public void testWsdlServletInvalidPathForWsdl() throws Exception {
/* 106 */     doWsdlServletRequest("/service/wsdl/NonExistentService.wsdl", true, 404);
/*     */   }
/*     */   
/*     */   public void testWsdlServletInvalidPathForXsd() throws Exception {
/* 110 */     doWsdlServletRequest("/service/wsdl/NonExistent.xsd", true, 404);
/* 111 */     doWsdlServletRequest("/service/wsdl/fred/NonExistent.xsd", true, 404);
/*     */   }
/*     */   
/*     */   public static void main(String[] args)
/*     */     throws Exception
/*     */   {
/*     */     
/*     */     try
/*     */     {
/* 120 */       TestUtil.runTest(TestWsdlServlet.class);
/*     */     } catch (Exception e) {
/* 122 */       System.out.println(e.getMessage());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestWsdlServlet.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */